# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=vuls
pkgver=v0.35.1.r3.g0ba85f8
pkgrel=2
epoch=1
_commit=0ba85f8fc51c0cb11b9b87269b3458cf4b3e429b
groups=('blackarch' 'blackarch-scanner')
pkgdesc='Vulnerability scanner for Linux/FreeBSD, agentless, written in Go.'
arch=('x86_64' 'aarch64')
url='https://github.com/future-architect/vuls'
license=('GPL-3.0-only')
depends=('sqlite')
makedepends=('git' 'go')
source=("git+https://github.com/future-architect/$pkgname.git#commit=$_commit")
sha512sums=('SKIP')

pkgver() {
  cd $pkgname

  ( set -o pipefail
    git describe --long --tags --abbrev=7 2>/dev/null |
      sed 's/\([^-]*-g\)/r\1/;s/-/./g' ||
    printf "%s.%s" "$(git rev-list --count HEAD)" \
      "$(git rev-parse --short=7 HEAD)"
  )
}

build() {
  cd $pkgname

  VERSION=$(git describe --tags --abbrev=0)
  REVISION=$(git rev-parse --short HEAD)
  BUILDTIME=$(date "+%Y%m%d_%H%M%S")

  GOFLAGS="-trimpath -buildmode=pie -mod=readonly -modcacherw"
  LDFLAGS="-X github.com/future-architect/vuls/config.Version=${VERSION}"
  LDFLAGS="$LDFLAGS -X github.com/future-architect/vuls/config.Revision=build-${BUILDTIME}_${REVISION}"

  GOPATH="$srcdir" go mod download

  GOPATH="$srcdir" go build \
    $GOFLAGS \
    -ldflags "$LDFLAGS" \
    -o $pkgname "./cmd/$pkgname"

  GOPATH="$srcdir" go build \
    $GOFLAGS \
    -ldflags "$LDFLAGS" \
    -o "$pkgname-scanner" ./cmd/scanner
}

package() {
  cd $pkgname

  install -Dm 755 $pkgname "$pkgname-scanner" -t "$pkgdir/usr/bin"
  install -Dm 644 -t "$pkgdir/usr/share/doc/$pkgname/" *.md
}

